<template>
  <el-dialog
    append-to-body
    :title="title"
    :visible.sync="dialogFormVisible"
    @close="close"
  >
    <el-form ref="form" :model="form" :rules="rules">
      <el-form-item label="当前数字id为:">
        {{ formtwo.digitalId }}
      </el-form-item>

      <el-form-item label="数字id(可编辑数字id后六位)" prop="digitalId">
        <el-input v-model="form.digitalId" placeholder="请输入更改后的数字id" />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </template>
  </el-dialog>
</template>

<script>
  import { updateDigitalId } from '@/api/noqiandao'

  export default {
    name: 'TableEdit',
    data() {
      return {
        actorScore: '', //当前状态
        actorScorewo: '', //修改后的分数分数
        form: {
          digitalId: '', //数字id
          id: '', //当前项的id
        },
        formtwo: {},
        rules: {
          digitalId: [
            {
              required: true,
              trigger: 'blur',
              message: '请输入更改后的数字id',
            },
            { pattern: /^(\d+)((?:\.\d+)?)$/, message: '请输入合法数字' },
            {
              min: 16,
              max: 16,
              message: '长度在16个字符',
              trigger: 'blur',
            },
          ],
        },
        title: '',
        dialogFormVisible: false,
      }
    },
    created() {},
    methods: {
      showEdit(row) {
        console.log(row)
        this.form.id = row.userId
        this.formtwo = row
        // this.title = '更改数字id'
        this.dialogFormVisible = true
      },
      close() {
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        this.dialogFormVisible = false
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg } = await updateDigitalId(this.form)
            console.log(msg)
            this.$baseMessage(msg, 'success', 'vab-hey-message-success')
            this.$emit('fetch-data')
            this.close()
          }
        })
      },
    },
  }
</script>
